﻿package com.yy.ui.containers {
    import com.yy.ui.events.UIEvent;
    
    import flash.display.*;
    import flash.geom.*;

    public class Box extends ContainerBase {

        private var _positionChange:Boolean = true;
        private var _stage:Stage;
        private var _contentPane:ContentPane;
        private var _cX:Number = 0;
        private var _cY:Number = 0;
        private var _rect:Rectangle;

        public function Box(){
            this._rect = new Rectangle();
            this._contentPane = new ContentPane();
            super.addChild(this._contentPane);
        }
        override protected function initComponent():void{
            this._stage = this.stage;
            super.initComponent();
        }
        override protected function updateDisplayList():void{
            super.updateDisplayList();
            this.positionUpdate();
        }
        override public function set width(_arg1:Number):void{
            super.width = _arg1;
            this._positionChange = true;
            if (this._stage){
                this._stage.invalidate();
            };
        }
        override public function set height(_arg1:Number):void{
            super.height = _arg1;
            this._positionChange = true;
            if (this._stage){
                this._stage.invalidate();
            };
        }
        public function get cX():Number{
            return (this._cX);
        }
        public function set cX(_arg1:Number):void{
            this._cX = _arg1;
            this._positionChange = true;
            if (this._stage){
                this._stage.invalidate();
            };
        }
        public function get cY():Number{
            return (this._cY);
        }
        public function set cY(_arg1:Number):void{
            this._cY = _arg1;
            this._positionChange = true;
            if (this._stage){
                this._stage.invalidate();
            };
        }
        protected function positionUpdate():void{
            if (((this._positionChange) && (this._contentPane))){
                this._positionChange = false;
                this._rect.x = this.cX;
                this._rect.y = this.cY;
                this._rect.width = width;
                this._rect.height = height;
                this._contentPane.scrollRect = this._rect;
                dispatchEvent(new UIEvent(UIEvent.ROLL));
            };
        }
        public function get maxCX():Number{
            if (this.cWidth > width){
                return ((this.cWidth - width));
            };
            return (0);
        }
        public function get maxCY():Number{
            if (this.cHeight > height){
                return ((this.cHeight - height));
            };
            return (0);
        }
        public function get cWidth():Number{
            return (this._contentPane.width);
        }
        public function get cHeight():Number{
            return (this._contentPane.height);
        }
        override public function addChild(_arg1:DisplayObject):DisplayObject{
            return (this._contentPane.addChild(_arg1));
        }
        override public function addChildAt(_arg1:DisplayObject, _arg2:int):DisplayObject{
            return (this._contentPane.addChildAt(_arg1, _arg2));
        }
        override public function getChildAt(_arg1:int):DisplayObject{
            return (this._contentPane.getChildAt(_arg1));
        }
        override public function getChildByName(_arg1:String):DisplayObject{
            return (this._contentPane.getChildByName(_arg1));
        }
        override public function getChildIndex(_arg1:DisplayObject):int{
            return (this._contentPane.getChildIndex(_arg1));
        }
        override public function removeChild(_arg1:DisplayObject):DisplayObject{
            return (this._contentPane.removeChild(_arg1));
        }
        override public function removeChildAt(_arg1:int):DisplayObject{
            return (this._contentPane.removeChildAt(_arg1));
        }
        override public function contains(_arg1:DisplayObject):Boolean{
            return (this._contentPane.contains(_arg1));
        }
        override public function setChildIndex(_arg1:DisplayObject, _arg2:int):void{
            this._contentPane.setChildIndex(_arg1, _arg2);
        }
        override public function swapChildren(_arg1:DisplayObject, _arg2:DisplayObject):void{
            this._contentPane.swapChildren(_arg1, _arg2);
        }
        override public function swapChildrenAt(_arg1:int, _arg2:int):void{
            this._contentPane.swapChildrenAt(_arg1, _arg2);
        }
        override public function get numChildren():int{
            return (this._contentPane.numChildren);
        }

    }
}

import com.yy.ui.core.UISprite;
import flash.display.*;

class ContentPane extends UISprite {

    public function ContentPane(){
    }
    override public function get width():Number{
        var _local4:DisplayObject;
        var _local1:Number = 0;
        var _local2:int = this.numChildren;
        var _local3:int;
        while (_local3 < _local2) {
            _local4 = getChildAt(_local3);
            if ((_local4.x + _local4.width) > _local1){
                _local1 = (_local4.x + _local4.width);
            };
            _local3++;
        };
        return (_local1);
    }
    override public function get height():Number{
        var _local4:DisplayObject;
        var _local1:Number = 0;
        var _local2:int = this.numChildren;
        var _local3:int;
        while (_local3 < _local2) {
            _local4 = getChildAt(_local3);
            if ((_local4.y + _local4.height) > _local1){
                _local1 = (_local4.y + _local4.height);
            };
            _local3++;
        };
        return (_local1);
    }

}
